package com.googlecode.imanager.core.base.style;

import com.googlecode.imanager.client.bridge.style.IBorder;
import com.googlecode.imanager.client.style.BorderStyle;
import com.googlecode.imanager.client.style.Color;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class ComputedBorder implements IBorder, ComputedAttribute<IBorder> {

    protected Color color;
    protected Integer width;
    protected BorderStyle style;

    public void mergeWith(IBorder o){
        if (o == null){
            return;
        }
        if (o.getColor() != null){
            color = o.getColor();
        }
        if (o.getWidth() != null){
            width = o.getWidth();
        }
        if (o.getStyle() != null){
            style = o.getStyle();
        }
    }

    @Override
    public void copyFrom(IBorder o) {
        if (o == null){
            color = null;
            width = null;
            style = null;
        } else {
            color = o.getColor();
            width = o.getWidth();
            style = o.getStyle();
        }
    }

    public Color getColor() {
        return color;
    }

    public Integer getWidth() {
        return width;
    }

    public BorderStyle getStyle() {
        return style;
    }

    @Override
    public final int getInset(){
        return width != null ? width.intValue()
             : color != null ? 1
             : style != null ? 1 : 0;
    }
        
}
